package com.example.javaeekeshe.controller;

import com.example.javaeekeshe.pojo.AdBean;
import com.example.javaeekeshe.service.IAdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/ad")
public class AdController {

    @Autowired
    IAdService adService;

    @RequestMapping("/toads")
    public String toads(Model model){
        List<AdBean> adBeans = adService.selectAllAd();
        model.addAttribute("ads",adBeans);
        return "/admin/index/ads";
    }

    @RequestMapping("/del/{id}")
    public String del(@PathVariable("id") Integer id){
        adService.del(id);
        return "redirect:/ad/toads";
    }

    @RequestMapping("/toadd")
    public String toadd(){
        return "/admin/index/addAd";
    }

    @RequestMapping("/addad")
    public String addad(AdBean adBean){
        adService.addAd(adBean);
        return "redirect:/ad/toads";
    }

    @RequestMapping("/update")
    public String update(AdBean adBean){
        adService.update(adBean);
        return "redirect:/ad/toads";
    }

}
